package com.adou.p2p.model;

import java.util.Date;

import javax.validation.constraints.NotNull;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import com.adou.p2p.domain.entiry.Product;
import com.fasterxml.jackson.annotation.JsonProperty;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ProductValue {
	@JsonProperty("id")
	private Long id;
	
	@NotNull
	@JsonProperty("proNum")
	private String proNum;
	
	@NotNull
	@JsonProperty("proName")
	private String proName;
	
	@JsonProperty("proLimit")
	private Long proLimit;
	
	@JsonProperty("annualized")
	private Double annualized;
	
	@JsonProperty("releaseDate")
	private Date releaseDate;
	
	public static ProductValue fromEntity(Product entiry){
		if(entiry == null) {
			return null;
		}
		
		return ProductValue.builder()
				.id(entiry.getId())
				.proNum(entiry.getProNum())
				.proName(entiry.getProName())
				.proLimit(entiry.getProLimit())
				.annualized(entiry.getAnnualized())
//				.releaseDate(entiry.getReleaseDate())
				.build();
	}
	
	public static Product fromEntity(ProductValue value){
		return Product.builder()
				.id(value.getId())
				.proNum(value.getProNum())
				.proName(value.getProName())
				.proLimit(value.getProLimit())
				.annualized(value.getAnnualized())
//				.releaseDate(value.getReleaseDate())
				.build();
	}
	
}
